/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TRIRzadeve;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.ReadWrite;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.net.ftp.FTPClient;

/**
 *
 * @author Irena
 */
public class FtpPovezava{
    
    private FTPClient client;
    private FileInputStream fis;

    public FtpPovezava() throws Exception {
        client = new FTPClient();
        client.connect("ftp.ribogojnica-pozeg.si");
        client.login("tose_care@ribogojnica-pozeg.si", "tosecare007");
        
        
        
    }
    
    public ArrayList<Model> vrniVseModele(){
        ArrayList<Model> modeli = new ArrayList<Model>();
        Dataset d = null;
        try{
            String[] names = client.listNames();
            

            for (String name : names) {
                System.out.println(name);
                if(name.contains(".rdf")) {
                    Model temp = ModelFactory.createDefaultModel();
                    InputStream is = client.retrieveFileStream(name);
                    try {
                        temp.read(is, "");
                        modeli.add(temp);
                        //d.begin(ReadWrite.WRITE);
                    } catch(Exception e) {}
                    client.completePendingCommand();
                }
            }   
           client.disconnect(); 
        } catch (Exception ex) {
          
          System.out.println(ex); 
        }
        return modeli;
    }
    
}
